using System;
using System.Windows.Forms;

namespace PlanningGIS.Win.Controls
{
   
    public partial class ComboListBox : UserControl
    {
        /// <summary>
        /// 
        /// </summary>
        public ComboListBox()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="leftitems"></param>
        /// <param name="rightitems"></param>
        public void SetDataSource(string[] leftitems, string[] rightitems)
        {
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            listBox1.Items.AddRange(leftitems);
            listBox2.Items.AddRange(rightitems);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string[] GetDataSource()
        {
            string[] strs = new string[listBox2.Items.Count];
            listBox2.Items.CopyTo(strs, 0);
            return strs;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void l2ra_Click(object sender, EventArgs e)
        {
            listBox2.Items.AddRange(listBox1.Items);
            listBox1.Items.Clear();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void r2la_Click(object sender, EventArgs e)
        {
            listBox1.Items.AddRange(listBox2.Items);
            listBox2.Items.Clear();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void r2ls_Click(object sender, EventArgs e)
        {
            foreach (object selectedItem in listBox2.SelectedItems)
            {
                listBox1.Items.Add(selectedItem.ToString());
            }
            for (int i = listBox2.SelectedItems.Count - 1; i >= 0; i--)
            {
                listBox2.Items.Remove(listBox2.SelectedItems[i]);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void l2rs_Click(object sender, EventArgs e)
        {
            foreach (object selectedItem in listBox1.SelectedItems)
            {
                listBox2.Items.Add(selectedItem.ToString());
            }
            for (int i = listBox1.SelectedItems.Count - 1; i >= 0; i--)
            {
                listBox1.Items.Remove(listBox1.SelectedItems[i]);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            foreach (object selectedItem in listBox1.SelectedItems)
            {
                listBox2.Items.Add(selectedItem.ToString());
            }
            for (int i = listBox1.SelectedItems.Count - 1; i >= 0; i--)
            {
                listBox1.Items.Remove(listBox1.SelectedItems[i]);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBox2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            foreach (object selectedItem in listBox2.SelectedItems)
            {
                listBox1.Items.Add(selectedItem.ToString());
            }
            for (int i = listBox2.SelectedItems.Count - 1; i >= 0; i--)
            {
                listBox2.Items.Remove(listBox2.SelectedItems[i]);
            }
        }
    }
}